package com.dj.download;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class DownloadActivity extends Activity implements View.OnClickListener {
    //    String
    private static final String TAG = "DownloadActivity";


    @Override
    public void onClick(View view) {
        v();


//        String array1[] = new String[]{""};
//        str.substring().substring().codePointAt()
//        for (int i = 0; i < array1.length; i++) {
//            Log.d(TAG, "");
////            String str = array1[i];
////            Strin
//        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dl);

        Log.d(TAG, "files:" + this.getBaseContext().getFilesDir());

        TextView tv = (TextView) findViewById(R.id.test);
        tv.setText(R.string.action_settings1);

        int stringid = getResources().getIdentifier("action_settings", "string", getPackageName());
        int tv1id = getResources().getIdentifier("textView", "id", getPackageName());
        String str = getResources().getString(stringid);

        tv = (TextView) findViewById(tv1id);
        tv.setText("用getPackageName()取：" + str);


//        stringid = getResources().getIdentifier("action_settings", "string", "com.dj.download");
        str = getResources().getString(R.string.action_settings);
        tv = (TextView) findViewById(R.id.tv2);
        tv.setText("固定从com.dj.download包中取：" + str);
        try {
            File file = new File(this.getBaseContext().getFilesDir(), "dl.txt");
            FileOutputStream fos = new FileOutputStream(file);
            fos.write("asdf;aldsfas;dfasd;fj".getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (R.id.action_settings == id) return true;
//
//        for (int i = 0; i < item.getGroupId(); i++) {
//              = item[i];
//
//        }
        return super.onOptionsItemSelected(item);

    }

    private void v() {

    }
}
